module CustomerRelationsManagement {
	//========================================= Exceptions =========================================
	exception RecordNotFound {
		int id;
		string name;
	};

	exception DBError {
		int errorCode;
		string errorText;
	};

	exception RecordNotCommitted {
		byte zero; // empty exceptions are not allowed by Ice
	};

	//========================================= Types =========================================
	
	struct datetime
	{
		byte hour;
		byte minute;
		byte second;
		
		byte day;
		byte month;
		short year;
	};
	
	enum OrderStatus { OPEN, DELIVERED };
	
	//========================================= Record Interfaces =========================================

	interface customer {
		int getId() throws RecordNotCommitted;
		void save() throws DBError;
		void delete() throws DBError, RecordNotCommitted;
		
		string getName();
		void setName(string name);
	};

	interface order {
		int getId() throws RecordNotCommitted;
		void save() throws DBError;
		void delete() throws DBError, RecordNotCommitted;
		
		int getCustomer();
		void setCustomer(int CustomerId);
		
		string getSrc();
		string getDst();
		void setSrc(string src);
		void setDst(string dst);
		
		float getWeight();
		void setWeight(float weight);
		
		datetime getDeadline();
		void setDeadline(datetime deadline);
		
		OrderStatus getStatus();
		void setStatus(OrderStatus status);
	};


	//========================================= Core Interface =========================================
	sequence<order*> OrderList;
	
	interface CRM {
		// NOTE: the Create<FOO>() functions only create an instance of the interface
		// when you're done filling in the values MAKE SURE TO CALL ITS SAVE METHOD

		customer* CreateCustomer();
		customer* LoadCustomerByName(string CustName) throws RecordNotFound, DBError;
		customer* LoadCustomerById(int CustId) throws DBError;

		order* CreateOrder();
		order* LoadOrderById(int OrderId) throws RecordNotFound, DBError;
		OrderList LoadOrderByCustomer(int CustId) throws DBError;
		OrderList LoadNewOrders() throws DBError, RecordNotFound;
	};
};

module Optimization {
	//========================================= Exceptions =============================================
	exception OptimizationEngineBusy {
		byte zero;
	};
	
	//========================================= Types ==================================================
	
	//========================================= Core Interface =========================================
	interface OptimizationEngine {
		void runTest() throws OptimizationEngineBusy;
	};
};

module Tracking {
	
	struct datetime
	{
		byte hour;
		byte minute;
		byte second;
		
		byte day;
		byte month;
		short year;
	};
	
	enum StopAction { PICKUP, DELIVERY };

	struct StopActionData
	{
		StopAction type;
		int orderID;
		int customerID;
		string src;
		string dst;
		float weight;
		datetime Deadline;
	};
	
	sequence<StopActionData>  stopactionlist;
	struct StopData
	{
		string location;
		stopactionlist actions;
	};
	
	sequence<StopData> stoplist;
	struct TruckData
	{
		string id;
		float capacity;
		stoplist stops;
	};
	
	sequence<TruckData> trucklist;
	struct RouteData
	{
		trucklist Trucks;
	};

	//========================================= Core Interface =========================================

	interface TrackingService {
		RouteData getAllData();
		void postNewRoutes(RouteData nrd);
	};
};
